#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>
    button {
        background: #758ef0;
        color: #FFF;
        border: none;
        border-radius: 15px;
    }
</style>
#end

#define content()
<div class="x-body">
    <label class="layui-form-label">组织名称</label>
    <div class="layui-input-inline">
        <div class="layui-input-inline">
            <input type="text" id="name" name="name" placeholder="组织名称" class="layui-input"/>
        </div>
        <div class="layui-input-inline" style="width : 80px">
            <button class="layui-btn" lay-submit="" id="search"><i class="layui-icon">&#xe615;</i>
            </button>
        </div>
    </div>
    <div class="layui-input-inline">
        <button class="layui-btn" id="reviewGroup">选择审查团体</button>
        &nbsp;&nbsp;
        <button class="layui-btn" id="profGroup">选择专业团体</button>
    </div>

    <!--隐藏id-->
    <input type="text" id="id" name="id"
           class="layui-input layui-disabled layui-hide" value="#(id)" required/>

    <div class="layui-row">
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>

    <div class="layui-input-inline x-center">
        <button class="layui-btn" id="OK" style="margin: 0 auto">完成</button>
    </div>

    <script type="text/html" id="barOption">
        #shiroHasPermission('/app/project/inviteReview')
        #[[
        {{#  if(!d.isInvite){ }}
        ]]#
        <a class="layui-btn layui-btn-xs" lay-event="invite">邀请</a>

        #[[
        {{# } else if(d.isInvite && d.status == '0'){ }}
        ]]#
        <a class="layui-btn layui-btn-disabled layui-btn-xs" disabled="disabled">待同意</a>

        #[[
        {{# } else if(d.isInvite && d.status == '1'){ }}
        ]]#
        <a class="layui-btn layui-btn-disabled layui-btn-xs" disabled="disabled">被拒绝</a>

        #[[
        {{# } else if(d.isInvite && d.status == '5'){ }}
        ]]#
        <a class="layui-btn layui-btn-disabled layui-btn-xs" disabled="disabled">分配人员中</a>

        #[[
        {{# } else if(d.isInvite && d.status == '6'){ }}
        ]]#
        <a class="layui-btn layui-btn-disabled layui-btn-xs" disabled="disabled">人员分配完成</a>

        #[[
        {{#  } }}
        ]]#
        #end
    </script>

</div>
#end

#define js()
<script type="text/javascript">
    var iObjType = 0;
    var projectId = "#(id)";

    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , layer = layui.layer;


        // 审核通过的表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-150'    //容器高度
            , contentType: 'application/json; charset=UTF-8'
            , cols: [[                  //标题栏
                {type: 'numbers', fixed: true, unresize: 'true'}
                , {field: 'name', title: '组织名称', width: 150, sort: true}
                , {field: 'scope', title: '服务范围', width: 200, sort: true}
                , {field: 'performance', title: '服务业绩', width: 200, sort: true}
                , {field: 'content', title: '专业内容', width: 250, sort: true}
                , {
                    title: '组织类型', width: 150, templet: function () {
                        if (iObjType == 0) {
                            return "审查团体";
                        } else if (iObjType == 1) {
                            return "专业团体";
                        }
                    }
                }
                , {fixed: 'right', title: '操作', align: 'center', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , url: '#(ctxPath)/app/project/reviewGroupTable?id=' + $('#id').val() + "&flag=" + iObjType
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , done: function (res, curr, count) {
            }
        });

        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'invite') {
                pop_show('邀请', '#(ctxPath)/app/project/reviewNum?id=' + data.id + '&projectId=' + projectId + '&orgType=' + iObjType, '300', '200', function () {
                    //？？？刷新考虑放这里，关闭当前pop_show
                    table.reload('dateTable', {
                        url: '#(ctxPath)/app/project/reviewGroupTable?id=' + $('#id').val() + "&flag=" + iObjType
                    });
                });
            }
        });

        $('#reviewGroup').click(function () {
            iObjType = 0;
            table.reload('dateTable', {
                url: '#(ctxPath)/app/project/reviewGroupTable?id=' + $('#id').val() + "&flag=" + iObjType
            });
        });

        $('#profGroup').click(function () {
            iObjType = 1;
            table.reload('dateTable', {
                url: '#(ctxPath)/app/project/reviewGroupTable?id=' + $('#id').val() + "&flag=" + iObjType
            });
        });

        $('#search').click(function () {
            if (iObjType === 0) {
                table.reload('dateTable', {
                    url: '#(ctxPath)/app/review_group/tableData?name=' + $('#name').val()
                });
            } else if (iObjType === 1) {
                table.reload('dateTable', {
                    url: '#(ctxPath)/app/prof_group/tableData?name=' + $('#name').val()
                });
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        $('#OK').click(function () {
            $.post('#(ctxPath)/app/project/judePeopleNum', {
                projectId: projectId
            }, function (data) {
                if (data.status) {
                    pop_close();
                } else if (!data.status) {
                    layer.msg("邀请填写的需求总人数至少为6个，请返回继续邀请，否则可能导致审查失败！", setTimeout(1000));
                    return false;
                }
            });
        });
    });

</script>
#end